//
//  Expansion.m
//  DemoRongCloud
//
//  Created by louyizhidu on 16/8/12.
//  Copyright © 2016年 louyizhidu. All rights reserved.
//

#import "Expansion.h"
#import "ExpansionCell.h"
#import "SectionCell.h"
#import "SectionCellModel.h"
@interface Expansion ()
{
    /**
     *  sectionCellModel数据
     */
    NSMutableArray* sectionCellModels;
}
@end

@implementation Expansion

- (void)viewDidLoad
{
    [super viewDidLoad];
    /**
     *  注册cell
     */
    [self.tableView registerNib:[UINib nibWithNibName:@"SectionCell"
                                               bundle:[NSBundle mainBundle]]
         forCellReuseIdentifier:sectionCell];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ExpansionCell"
                                               bundle:[NSBundle mainBundle]]
         forCellReuseIdentifier:rowsCell];
    sectionCellModels=[[NSMutableArray alloc] init];
    for (int i=0; i<5; i++)
    {
        SectionCellModel* model=[[SectionCellModel alloc] init];
        model.scmExpansion=NO;
        [sectionCellModels addObject:model];
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return sectionCellModels.count;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    /**
     *  默认显示提示cell
     */
    SectionCellModel* model=sectionCellModels[section];
    return model.scmExpansion?5:1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    if (indexPath.row==0)
    {
      SectionCell*  section= (SectionCell*)[tableView dequeueReusableCellWithIdentifier:sectionCell
                                                                               forIndexPath:indexPath];
        section.scModel=sectionCellModels[indexPath.section];
        [section scSelectedInit:^
        {
            [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]
                     withRowAnimation:(UITableViewRowAnimationFade)];
        }];
        cell=section;
        
    }
    else
    {
        cell=[tableView dequeueReusableCellWithIdentifier:rowsCell
                                             forIndexPath:indexPath];
    }
    return cell;
}

/*
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
